package org.kzwl.book.controller.web;

import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.kzwl.comm.pojo.ResponseData;
import org.kzwl.comm.pojo.bo.AdminBO;
import org.kzwl.comm.pojo.bo.DeleteAdminBO;
import org.kzwl.comm.pojo.bo.LoginAdminBO;
import org.kzwl.comm.pojo.bo.QueryAdminBO;
import org.kzwl.entity.web.Admin;
import org.kzwl.service.web.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

@Slf4j
@RestController
@RequestMapping("/admin")
@Api("PC管理员")
public class AdminController {


    @Autowired
    AdminService adminService;

    @PostMapping("/login")
    public ResponseData<String> login(@RequestBody LoginAdminBO loginAdminBO)
    {
        return adminService.login(loginAdminBO);
    }


    @GetMapping("/get_info")
    public String getInfo(HttpServletRequest request)
    {
        String token = request.getHeader("token");
        return token;
    }


    @PostMapping("/saveIn")
    public ResponseData<Void> saveIn(@RequestBody @Valid AdminBO adminBO)
    {
        return adminService.saveIn(adminBO);
    }

    @PostMapping("/queryPage")
    public ResponseData<IPage<Admin>> queryPage(@RequestBody QueryAdminBO queryAdminBO)
    {
        return adminService.queryPage(queryAdminBO);
    }

    @PostMapping("/deleteById")
    public ResponseData<Void> deleteById(@RequestBody DeleteAdminBO deleteAdminBO)
    {
        return adminService.deleteById(deleteAdminBO);
    }

}
